﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TicketMovie.User
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        private DataClasses1DataContext dc = new DataClasses1DataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                List<Doawlist> list = new List<Doawlist>();

                var fl2 = dc.Films.Where(kq=> kq.notes.Equals("now")).Distinct().ToList();
                foreach( Film f in fl2 ){
                    list.Add(new Doawlist(f.code_flim.ToString(),f.film_name,f.film_format  ));
                }
                this.DropDownList_movi.DataSource = list;
                this.DropDownList_movi.DataTextField = "textfiel";
                this.DropDownList_movi.DataValueField = "valuefiel";
                this.DropDownList_movi.DataBind();
                this.DropDownList_movi.Items.Insert(0, new ListItem("Please select"));



                var fl = dc.Films.Where(kq => kq.notes.Equals("now")).Take(12).ToList();
                this.Repeater1.DataSource = fl;
                this.Repeater1.DataBind();

                var fl1 = dc.Films.Where(kq => kq.notes.Equals("soon")).Take(12).ToList();
                this.Repeater2.DataSource = fl1;
                this.Repeater2.DataBind();

            }
        }

        protected void DropDownList_movi_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.DropDownList_movi.SelectedValue == "Please select")
            {
                return;
            }
            int code = Convert.ToInt32(this.DropDownList_movi.SelectedValue);

            List<Doawlist> list = new List<Doawlist>();
            var dst = dc.Time_movies.ToList();
            var dstg = dc.Time_Films.ToList();
            foreach (Time_movy ds in dst)
            {
                foreach (Time_Film ds1 in dstg)
                {
                    if (ds.code_times.Equals(ds1.code_times) && ds1.code_flim == code)
                    {
                        list.Add(new Doawlist(ds.code_times, ds.hours.ToString(), ds.minutes.ToString()));
                    }
                }
            }



            //var products = (from od in this.dc.Time_movies
            //                join p in this.dc.Time_Films on od.code_times equals p.code_times
            //                where p.code_flim == code
            //                select new { hours = od.hours, minutes = od.minutes, valuefiel = p.code_flim }).ToList();

            //for (int i = 0; i < products.Count; i++)
            //{
            //    list.Add(new Doawlist(products[i].valuefiel.ToString(), products[i].hours.ToString(), products[i].minutes.ToString()));
            //}


            this.DropDownList_time.DataSource = list;
            this.DropDownList_time.DataTextField = "textfiel";
            this.DropDownList_time.DataValueField = "valuefiel";
            this.DropDownList_time.DataBind();
            this.DropDownList_time.Items.Insert(0, new ListItem("Please select"));
        }

        protected void DropDownList_time_SelectedIndexChanged(object sender, EventArgs e)
        {
            string code = this.DropDownList_time.SelectedValue;
            this.DropDownList_day.DataSource = dc.search_date(code);
            this.DropDownList_day.DataTextField = "date";
            this.DropDownList_day.DataValueField = "code_days";
            this.DropDownList_day.DataBind();
            this.DropDownList_day.Items.Insert(0, new ListItem("Please select"));
        }
    }
}